package com.wang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.mapper.ParkingSpaceMapper;
import com.wang.entity.ParkingSpace;
import com.wang.service.ParkingSpaceService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 33115
* @description 针对表【parking_space】的数据库操作Service实现
* @createDate 2024-06-17 11:12:44
*/
@Service
public class ParkingSpaceServiceImpl extends ServiceImpl<ParkingSpaceMapper, ParkingSpace>
    implements ParkingSpaceService{

    @Override
    public void addParkingSpace(ParkingSpace parkingSpace) {
        if (parkingSpace == null || StringUtils.isAnyBlank( parkingSpace.getCarNumber())) {
            System.out.println("车位信息不能为空");
        }
        save(parkingSpace); // 使用MyBatis-Plus的save方法直接保存
    }


    @Override
        public List<ParkingSpace> getParkingSpace(Integer spaceNumber, Integer carNumber) {
            LambdaQueryWrapper<ParkingSpace> queryWrapper = new LambdaQueryWrapper<>();

            // 分别检查并设置查询条件
            if (spaceNumber != null) {
                queryWrapper.eq(ParkingSpace::getSpaceNumber, spaceNumber); // 根据spaceNumber精确匹配
            }

            if (carNumber != null) {
                queryWrapper.eq(ParkingSpace::getCarNumber, carNumber); // 根据carNumber精确匹配
            }

            // 确保至少有一个查询条件被设置
            if (queryWrapper.isEmptyOfWhere()) {
                throw new IllegalArgumentException("至少需要提供spaceNumber或carNumber进行查询");
            }

            return list(queryWrapper);
        }

    }




